package logic;
/**
 * 
 * @author tomek
 *
 */
public class MapField implements Comparable<MapField> {

	private final int positionX;
	private final int positionY;
	private FieldType type;

	// Heuristic distance
	private double H = 0.0;

	// Total distance
	private double F = 0.0;

	// Distance from neighbour field
	private double G = 0.0;

	private MapField father = null;

	/**
	 * 
	 * @param positionX
	 * @param positionY
	 */
	public MapField(int positionX, int positionY) {
		this.positionX = positionX;
		this.positionY = positionY;
		this.setType(FieldType.WAY);
	}

	/**
	 * 
	 * @param positionX
	 * @param positionY
	 * @param type
	 */
	public MapField(int positionX, int positionY, FieldType type) {
		this.type = type;
		this.positionX = positionX;
		this.positionY = positionY;
	}

	/**
	 * 
	 */
	public void computeF() {
		F = G + H;
	}

	/* overrides section */
	@Override
	public boolean equals(Object obj) {
		if (obj == this)
			return true;
		if (!(obj instanceof MapField))
			return false;

		MapField comparedObject = (MapField) obj;

		if ((this.getPositionX() == comparedObject.getPositionX())
				&& (this.getPositionY() == comparedObject.getPositionY()))
			return true;
		else
			return false;
	}

	@Override
	public int hashCode() {
		Integer x = new Integer(positionX);
		Integer y = new Integer(positionY);
		int hash = 1;
		hash = hash * 31 + x.hashCode();
		hash = hash * 31 + y.hashCode();
		return hash;
	}

	@Override
	public int compareTo(MapField o) {
		final int equal = 0;
		final int before = -1;
		final int after = 1;
		if (o == this)
			return 0;
		if (this.getF() < o.getF())
			return before;
		else if (this.getF() > o.getF())
			return after;
		else
			return equal;
	}

	/* getters and setters section */
	public void setFather(MapField father) {
		this.father = father;
	}

	public MapField getFather() {
		return father;
	}

	public void setH(double h) {
		H = h;
	}

	public double getH() {
		return H;
	}

	public void setG(double g) {
		G = g;
	}

	public double getG() {
		return G;
	}

	public void setF(double f) {
		F = f;
	}

	public double getF() {
		return F;
	}

	public int getPositionX() {
		return positionX;
	}

	public int getPositionY() {
		return positionY;
	}

	public void setType(FieldType type) {
		this.type = type;
	}

	public FieldType getType() {
		return type;
	}

}
